

// #include "gui_logist.h"

//#if 0

#ifndef __GUI_LOGIST_H__
#define __GUI_LOGIST_H__

#include "gw_ktj_api_config.h"

/*
01H 缺A相。 02H 缺B相。 03H 缺C相。
04H  A相电压超高限。05H  A相电压超低限。
06H  B相电压超高限。07H  B相电压超低限。
08H  C相电压超高限。09H  C相电压超低限。
0AH  A相电流超高限。0BH  B相电流超高限。
0CH  C相电流超高限。 0EH      AD1路电压报警。
0FH  AD2路电压报警。10H  光耦输入1报警。
11H  光耦输入2报警。12H  水浸报警
*/

#include <bits/pthreadtypes.h>
#include <stdint.h>




typedef enum {
	ALM_PHASE_LOSE_A = 1,
	ALM_PHASE_LOSE_B,
	ALM_PHASE_LOSE_C,
	ALM_VOLTA_HI,
	ALM_VOLTA_LOW,
	ALM_VOLTB_HI,
	ALM_VOLTB_LOW,
	ALM_VOLTC_HI,
	ALM_VOLTC_LOW,
	ALM_CURRA_HI,
	ALM_CURRB_HI,
	ALM_CURRC_HI,
	ALM_NULL,
	ALM_ADC1,
	ALM_ADC2,
	ALM_DI1,
	ALM_DI2,
	ALM_DI3,
	ALM_DI4,
}gw_alarm_t;




typedef struct  {
  unsigned int lng;
  unsigned int lat;
  unsigned int tz;
  unsigned int ct;
  unsigned int vt;
}gw_param_cfg_t;

typedef struct {
	unsigned int enable;
	int high_volt_a;
	int low_volt_a;
	int high_volt_b;
	int low_volt_b;
	int high_volt_c;
	int low_volt_c;
	
}alarm_enable_t;


typedef struct {
	char ip[16];
	unsigned int port;
}ip_cfg_t;


#pragma pack(1)

typedef struct {
	char swVer[16];
	char hwVer[16];
	char plcMac[16];
	char bleMac[16];////"bleMac":"network_monitor-v1.1.3"  //11*2=22 ----数据溢出-----不能在这里改----否则masterId对不上
	char ethMac[16];//ethMac   eth_mac
	char wifiMac[16];//wifiMac  wifi_mac
	char masterId[32];
	char pid_gateway[32];
	char gatewayId[32];
	char panel_cnnttype[8];
	unsigned char sub_dev_linkmode;  // 子设备链接方式： 6：plc3921
	unsigned char netowrk_mode;      //  3：wifi，5：4G，7：eth
	unsigned char wiring_mode;     // 电表线
	unsigned char rsv;
	gw_param_cfg_t gw_param;
	char usrMsg[256];//16*5+32*4+8+5*4+4
}nv_gw_msg_t;

 
typedef struct {
	char bleMac[32];////"bleMac":"network_monitor-v1.1.3"  //11*2=22 
	char usrMsg[256];
} gui_gw_com_t;


//#if    SMART_ENABLE          

//----测试数据------

//#define   USER_DATA_BUF_MAX     (256U)
#define   NV_GW_MSG_MAX     (256U)


#if 0
typedef	 union 
{
		uint8_t  Buffer[NV_GW_MSG_MAX];   //16*6+32*3+8+4+5*4=224
		struct         
		{					
			char swVer[16];
			char hwVer[16];
			char plcMac[16];
			char bleMac[16];   //"bleMac":"network_monitor-v1.1.3"  //11*2=22 
			char ethMac[16];  //ethMac   eth_mac
			char wifiMac[16];  //wifi_mac
			char masterId[32];
			char pid_gateway[32];
			char gatewayId[32];
			char panel_cnnttype[8];
			unsigned char sub_dev_linkmode;  // 子设备链接方式： 6：plc3921
			unsigned char netowrk_mode;      //  3：wifi，5：4G，7：eth
			unsigned char wiring_mode;     // 电表线
			unsigned char rsv;
			gw_param_cfg_t gw_param;
	
		} Reg;
	
}  nv_gw_msg_u;

#endif

typedef	 union 
{
		uint8_t  Buffer[NV_GW_MSG_MAX];   //16*6+32*3+8+4+5*4=224
		struct         
		{					
			char swVer[16];
			char hwVer[16];
			char plcMac[16];
			char bleMac[16];
			char eth_mac[16];
			char wifi_mac[16];
			char masterId[32];
			char pid_gateway[32];
			char gatewayId[32];
			char panel_cnnttype[8];
			unsigned char sub_dev_linkmode;  // 子设备链接方式： 6：plc3921
			unsigned char netowrk_mode;      //  3：wifi，5：4G，7：eth
			unsigned char wiring_mode;     // 电表线
			unsigned char rsv;
			gw_param_cfg_t gw_param;
	
		} Reg;
	
}  nv_gw_msg_u;



#pragma pack()

extern  nv_gw_msg_u nv_gw_msg_obj;



typedef struct {
	char ip[16];
	char mask[16];
	char gateway[16];		
	unsigned int port;
} eth_info_t;



typedef struct {

nv_gw_msg_t       nv_gw_msg;
//nv_gw_msg_u       nv_gw_msg;
ip_cfg_t          ip_cfg;
gw_param_cfg_t    gw_param_cfg;
alarm_enable_t    alarm_enable;
eth_info_t  eth0;     // 以太网上网
eth_info_t  eth1;     // 网关为4G 网卡

 char workNet[8];        //“eth0”为以太网上网   //“eth1”为使用4G 上网 
 unsigned int   csq;     // 4G 信号强度


} gui_gw_param_st;




#if   F133_ktj_gw_app_v2_4_19_Enable   
#define  nv_gw_msg_file_path   "/mnt/UDISK/iot_gw/data/gw_msg.dat" 
#else
#define  nv_gw_msg_file_path   "/mnt/UDISK/gw_plc/data/gw_msg.dat" 
#endif 




#define LOCAL_MAC_STR_SIZE    18
#define LOCAL_IP_STR_SIZE     16

////--WEB服务器显示，LCD显示用的全局变量----字符串格式存储------------------------

#pragma pack(1)

typedef	struct        
{			
char local_mac[LOCAL_MAC_STR_SIZE];    // 24:0a:c4:c9:70:85 edited by donnie liang 20170519  char MAC[17]={0};,17有问题，结束符丢失
char local_ip[LOCAL_IP_STR_SIZE];     // 111.111.111.111  
char subnet[LOCAL_IP_STR_SIZE];       //edited by donnie liang 20170519
char gateway[LOCAL_IP_STR_SIZE];      //edited by donnie liang 20170519
char port[6];		    //65535
	
}  EthString_st;


#pragma pack( )



//extern EthParam_st     EthParam;
extern EthString_st    EthString;

extern  gui_gw_com_t  gui_gw_com;


extern gui_gw_param_st   gui_gw_param;

extern unsigned int  gui_msg_id; 

 extern pthread_t gui_logist_app_tid;


void gui_logist_init(void );

void gui_logist_tick_sec(void );


char* get_gateway_id(void);
//hwVer=1.0.0
//swVer=2.4.18
char* get_gateway_swVer(void);
char* get_gateway_hwVer(void);
uint8_t gui_get_4G_CSQ(void);

char* get_plc_mac(void);
char* get_eth_mac(void);
char* get_ble_mac(void);


gui_gw_param_st* gui_get_gw_param(void );




#endif    //------- __GUI_LOGIST_H__ 




